import request from '@/config/axios'

// 保险 VO
export interface InsuranceVO {
  id: number // id
  customerId: number // 客户编号
  customerName?: string // 客户名称
  createTime: Date // 创建时间
  updateTime: Date // 更新时间
  creator: string // 创建人
  creatorName?: string // 创建人名称
  updater: string // 修改人
  updaterName?: string // 修改人名称
  auditStatus: number // 审核状态
  processInstanceId?: string // 审核流程实例编号
}

// 保险 API
export const InsuranceApi = {
  // 查询保险分页
  getInsurancePage: async (params: any) => {
    return await request.get({ url: `/crm/insurance/page`, params })
  },

  // 查询保险详情
  getInsurance: async (id: number) => {
    return await request.get({ url: `/crm/insurance/get?id=` + id })
  },

  // 保险信息审核
  submit: async (ids: number[],isReCreate: boolean) => {
    return await request.put({ url: `/crm/insurance/submit`,params: { ids: ids.join(',') ,isReCreate: isReCreate }} )
  },

  // 查询保险详情
  getInsuranceByCustomerId: async (customerId: number) => {
    return await request.get({ url: `/crm/insurance/getByCustomerId?customerId=` + customerId })
  },

  // 新增保险
  createInsurance: async (data: InsuranceVO) => {
    return await request.post({ url: `/crm/insurance/create`, data })
  },

  // 修改保险
  updateInsurance: async (data: InsuranceVO) => {
    return await request.put({ url: `/crm/insurance/update`, data })
  },

  // 删除保险
  deleteInsurance: async (id: number) => {
    return await request.delete({ url: `/crm/insurance/delete?id=` + id })
  },

  // 导出保险 Excel
  exportInsurance: async (params) => {
    return await request.download({ url: `/crm/insurance/export-excel`, params })
  },

// ==================== 子表（保险信息） ====================

  // 获得保险信息列表
  getInsuranceInfoListByInsuranceId: async (insuranceId) => {
    return await request.get({ url: `/crm/insurance/insurance-info/list-by-insurance-id?insuranceId=` + insuranceId })
  },
}
